import Vue from 'vue'
import Vuex from 'vuex'

import { getItem, setItem } from '../utils/storage'

Vue.use(Vuex)

const TOKEN_KEY = 'TOUTIAO_USER'

export default new Vuex.Store({
  state: {
    // user 对象:存储当前登录用户信息(token数据等)
    user: getItem(TOKEN_KEY)
  },
  actions: {},
  mutations: {
    setUser(state, data) {
      state.user = data
      // 为了防止刷新丢失,我们需要把数据被分到本地存储
      setItem(TOKEN_KEY, state.user)
    }
  },
  modules: {}
})
